﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Windows;
using Cinchoo.Core;
using Cinchoo.Core.Reflection;
using Cinchoo.Core.Text.RegularExpressions;
using ChoWorkflowServer.Model;

namespace ChoWorkflowDashboard
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : Application
    {
        [STAThread()]
        [LoaderOptimization(LoaderOptimization.MultiDomainHost)]
        static void Main()
        {
            ChoAssemblySettings.Me.AddExcludeAssemblyWildCard("*PlugIns*");
            ChoApplication.Run(null);
        }
    }

    [ChoApplicationHost]
    public class ApplicationHost : ChoApplicationHost
    {
        public static ApplicationHost Default
        {
            get;
            private set;
        }

        private Lazy<ChoMainWindow> _window = new Lazy<ChoMainWindow>(() => new ChoMainWindow());

        public ApplicationHost()
        {
            Default = this;
        }

        protected override void ApplyGlobalApplicationSettingsOverrides(ChoGlobalApplicationSettings obj)
        {
            obj.TrayApplicationBehaviourSettings.TurnOn = true;
            obj.TrayApplicationBehaviourSettings.ContextMenuSettings.DisplayShowMainWndMenuItem = true;
            obj.TrayApplicationBehaviourSettings.ContextMenuSettings.DisplayHelpMenuItem = false;
            obj.TrayApplicationBehaviourSettings.ContextMenuSettings.DisplayAboutMenuItem = false;
            obj.TrayApplicationBehaviourSettings.ContextMenuSettings.DisplayShowInTaskbarMenuItem = false;
            obj.TrayApplicationBehaviourSettings.BalloonTipText = "WorkflowDashboard is still running...";
            obj.TrayApplicationBehaviourSettings.TooltipText = "WorkflowDashboard";

            base.ApplyGlobalApplicationSettingsOverrides(obj);
        }

        protected override void AfterAppFrxSettingsLoaded(object obj)
        {
            if (obj is ChoAppFrxSettings)
            {
            }
            else if (obj is ChoCodeBaseSettings)
            {
                ((ChoCodeBaseSettings)obj).IncludeAppBaseSubDirectories = false;
            }

            base.AfterAppFrxSettingsLoaded(obj);
        }

        protected override void OnStart(string[] args)
        {
            base.OnStart(args);
        }

        public override object MainWindowObject
        {
            get
            {
                return new ChoMainWindow();
            }
        }

        public override object ApplicationObject
        {
            get
            {
                App app = new App();
                app.InitializeComponent();
                return app;
            }
        }
    }
}
